<template>

  <div>
   <div class="home-bar page-bar position-fixed ">
        
       
        <mt-header title="家庭医生">
       
      </mt-header>
      </div>
    <!--
    <div class="loginImg " style="z-index:-1" > </div >
      <img class="loginImg" style="z-index:-2;" src="../assets/login.png">
       <div class="loginImg " style="z-index:-3;background:#009688;" > </div >-->



      <div >
     
      <!--<div class="logininputDiv" >
        <div style="height:63px;"></div>
        <h3 style="color:#e6e3e3;">在线咨询</h3>
       <div style="height:63px;"></div>
        <input class="logininput " placeholder="  账号" type="text" v-model="account"  maxlength="15" />
        <div style="height:8px;" ></div>
        <input  class="logininput"  placeholder="  密码" type="password" v-model="password" maxlength="15"/>
        <div style="height:16px;" ></div>
        <div  @click="login()"  class="logininput loginButton login-border-radius-4" >
          登陆
        </div>
          <div @click="loginAlert()" class="logininput loginButtonBottomText " style="text-align:right;line-height: 36px;" >
          忘记密码?
        </div>
        </div>-->

      </div>

                <!--<div  v-bind:style="{height:clientHeight-368+'px'}"></div>
        
                <div  class="bottomText  text-align-center font-size-12 color-ffffff">
                  
                <div>盐池县卫生和计划生育局版权所有</div>
                <div>陕西三思信息技术有限公司技术支持</div>
                </div>-->
              
         
      
     
  </div>
</template>

<script>

import config from '../config/config.js';
import  http from '../config/http.js';

import { Toast ,Indicator} from 'mint-ui';


export default {
  name: 'login',
  data () {
    return {
      msg: 'login',
      account:'',//18391009391 
      password:'',//123456
      //设备高度
      clientHeight:document.documentElement.clientHeight,
      LoginObjParams:'',//跳转传值
    }
  },
  mounted(){
      //Indicator.open();  
    
   
    
    //this.WeChatPublicNumberOpenId();   
    //事例
    //通知跳转http://jjtyh.cpcs.top/SmartHospitalSystem/im/index.html?uuid=5902cafb644c42fcbdd1197eb9d2a041&WeChatAlertTips=true&doctorId=22&doctorName=郭彩霞
    //微信公众号跳转http://jjtyh.cpcs.top/SmartHospitalSystem/im/index.html?uuid=5902cafb644c42fcbdd1197eb9d2a041

    //截取userid  
    let useridString='';
    if(window.location.href.indexOf("?") != -1 ){//-1 没 
         
         let windowLocationHrefSplit=(window.location.href).split('?')[1].replace(/#/g, "").replace(/[/]/g, "").split('&');//过滤 # / 通知跳转的拼接使用色是^不是&
         
         console.log(windowLocationHrefSplit);
         var LoginObj={
             'uuid':'',//uuid
             'WeChatAlertTips':'',//有值就说明是从微信通知登录过来的
             'doctorId':'',//微信通知登录过来 所需的doctorId
             'doctorName':'',//微信通知登录过来 所需的doctorName
         };
         var windowLocationHrefSplitSplitArrCollect=[];
         for(var z in windowLocationHrefSplit){
           var windowLocationHrefSplitSplitArr=windowLocationHrefSplit[z].split('=');
             for(var i in windowLocationHrefSplitSplitArr){
                    //windowLocationHrefSplitSplitArrCollect
                    windowLocationHrefSplitSplitArrCollect.push(windowLocationHrefSplitSplitArr[i]);
             }
         }
         
         for(var x in windowLocationHrefSplitSplitArrCollect){
             
             if(windowLocationHrefSplitSplitArrCollect[x]=='uuid' || windowLocationHrefSplitSplitArrCollect[x]=='UUid' ||  windowLocationHrefSplitSplitArrCollect[x]=='UUId'){
                LoginObj.uuid=windowLocationHrefSplitSplitArrCollect[Number(x)+1];
                
             }else if(windowLocationHrefSplitSplitArrCollect[x]=='WeChatAlertTips'){
                LoginObj.WeChatAlertTips=windowLocationHrefSplitSplitArrCollect[Number(x)+1];
               
             }else if(windowLocationHrefSplitSplitArrCollect[x]=='doctorId'){
                LoginObj.doctorId=windowLocationHrefSplitSplitArrCollect[Number(x)+1];
              
             }else if(windowLocationHrefSplitSplitArrCollect[x]=='doctorName'){
                LoginObj.doctorName=windowLocationHrefSplitSplitArrCollect[Number(x)+1];
               
             }
         }  
         
         
          //console.log(LoginObj);
         
        //  if(windowLocationHrefSplitSplitArrCollect.indexOf('WeChatAlertTips')==-1){
        //  //微信公众号跳转登录   
        //  useridString=LoginObj.uuid;
        //  }else{
        //  //微信通知跳转登录 跳转的时候传值到首页
        //   useridString=LoginObj.uuid;
        //  }

         useridString=LoginObj.uuid;
         this.LoginObjParams=LoginObj;
    }else{
          useridString='';
    }
    
    
    
    
     if( useridString!=''){
        //console.log(useridString)
        //userid 已经改名uuid 暂时不影响
         window.sessionStorage.setItem("userid",JSON.stringify(useridString));
          //默认使用userId 登录
         this.ObtainingUserVal(useridString);
     }
    
   
  },
 methods:{
   
    
      //open id登录 获取用户openId=>(暂时无用)
   WeChatPublicNumberOpenId(){
      let locationUrl=('http://ycapp.sunthinks.cn/SmartHospitalSystem/im/index.html?openid=o2nIP1r9_LsnGorIZEBPeftxCgSk').split('?');
      
      //let  locationUrl=(location.href).split('?');

      for(var z in locationUrl){
          if((locationUrl[z]).substr(0,6)=='openid'){
            var demo=((locationUrl[z]).substr(7)).split('#');
            window.sessionStorage.setItem("openId",JSON.stringify(demo[0]));
            //alert(location.href);
            //alert(JSON.parse(sessionStorage.getItem("openId")));
            console.log(demo)
            break;
          }
      }
      //openId登录
      this.openIDLogin(demo[0]);



    },
     //openId登录(取消)
    openIDLogin(openId){
            let openIdLoginObj={
                openId:openId,//openId
              }
            http.post(config.HttpDomain+config.openIdLogin,openIdLoginObj)
            .then((value)=>{
                console.log(value) 
                
                if(value.message=='1'){
                //登陆成功 并且登录
                //this.$router.replace({ path: '/home' });  
                   }else{  
                      Toast({
                      message: value.error?value.error:'登录失败',
                      position: 'bottom',
                      duration: 2000
                    });
                }
                
            },(error)=>{
                console.log('error');
                Toast({
                message: '登录失败',
                position: 'bottom',
                duration: 2000
              });
                
            })

    },
    //userid 登录=>(直接获取用户信息)
    ObtainingUserVal(userId){
          Indicator.open();  
           let ObtainingUserObj={
                
                op:'queryRecordsByUuid',
                UUID:userId,
                //UUID:'7fe6ce76581944ee93c446437c125e36',
              }
            http.post(config.UUIDLogin,ObtainingUserObj)
            .then((value)=>{
               Indicator.close();
                console.log(value) 
                
                if(value.total=='1' ){
                  //登陆成功 并且登录
                  if( value.rows.length!=0){
                      //数据结构按照以前的储存
                      let valueUser={
                          id:value.rows[0].uuid,
                          name:value.rows[0].name,
                      }
                      window.localStorage.setItem('loginStorageLocalStorage',JSON.stringify(valueUser));
                      
                     this.$router.replace({ path: '/home',name:'home',params:{LoginObj:this.LoginObjParams} });  
                  }else{
                      Toast({
                      message: '登录失败',
                      position: 'bottom',
                      duration: 2000
                    });
                  }
                  
                    
                   }else{  
                      Toast({
                      message: value.error?value.error:'登录失败',
                      position: 'bottom',
                      duration: 2000
                    });
                }
                
            },(error)=>{
              Indicator.close();
                Toast({
                message: '登录失败 ',
                position: 'bottom',
                duration: 2000
              });
                
            })
    },

    
      loginAlert(){
        alert('请联系管理员恢复初始密码!')
      },
      login(){
          //this.$router.push({ path: '/home' });
        let HttpDomainObj={
          loginName:this.account,
          password:this.password,
          type:'',//此处传1=>不填
        }
        if(this.account!='' && this.password!=''){
       http.post(config.HttpDomain+config.login,{loginName:this.account, password:this.password,type:''})
       .then((value)=>{
          //console.log(value) 
          
          if(value.message=='1'){
               
                
               window.localStorage.setItem('loginStorageLocalStorage',JSON.stringify(value.user));
               // this.$router.push({ path: '/home' });
               this.$router.replace({ path: '/home' });  
               
                
          }else{  
                Toast({
                message: value.error?value.error:'登录失败',
                position: 'bottom',
                duration: 2000
              });
          }
          
       },(error)=>{
          console.log('error');
          Toast({
          message: '登录失败',
          position: 'bottom',
          duration: 2000
        });
          
       })
       }else{
           Toast({
          message: '账号密码不能为空',
          position: 'bottom',
          duration: 2000
        });
       }
      },
      

     
   }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.mint-header{
  height:56px;
   background: -webkit-linear-gradient(left, #1de5e2, #b588f7) !important;
   
}
.loginImg{
  width:100%;
  /*height:100%;*/
  position:absolute;
  /*z-index:-1!important;*/
}
.logininput{
  width:80%;
  height:32px;
   margin:0 auto;
  
}
.logininputDiv{
  text-align:center;
 
}
input{
      color:#888888;
  }
.loginButton{ 
    border:1px solid #ddd;
    font-size:14px;
    background:rgba(230,227,227,.0.3);
    color:#ffffff;
    line-height:35px;
    box-shadow:1px 1px 1px 0px #333;
}
.loginButtonBottomText{ 
   
    font-size:13px;
   
    color:#ffffff;
    bottom:0;
}
.bottomText{
  width:100%;
  height:43px;
  
  
  
}
</style>
